import http from '@/plugins/aixos'
import { orderModel } from '@/types/model'

export const addOrder = (data: orderModel) => {
  return http.request({
    url: '/order',
    method: 'POST',
    data,
  })
}

/**
 * 删除所有order
 * @param sectionId 区段的ID
 * @returns
 */
export const delOrders = (sectionId: number) => {
  return http.request({
    url: `order/orders/${sectionId}`,
    method: 'DELETE',
  })
}

/**
 * 删除单个order
 * @param id order的ID
 * @returns
 */
export function delOrder(id: number) {
  return http.request({
    url: `order/${id}`,
    method: 'DELETE',
  })
}

export function findAllOrder(args: Record<string, any>) {
  const url =
    '/order?' +
    Object.entries(args)
      .map(([key, value]) => `${key}=${value}`)
      .join('&')
  return http.request<orderModel[]>({ url })
}
